<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>iComet long-polling demo</title>
		<script src="js/jquery-1.9.1.js"></script>
		<script src="js/icomet.js"></script>
</head>
<body>

<pre style="height:200px; width: 600px; border: 1px solid #999; overflow: auto; background: #eee; padding: 8px;">
## How to Use?

1. start icomet-server

2. open long-polling.html in web browser(Firefox, Chrome, Safari, etc)

3. open a command line terminal, execute

curl "http://127.0.0.1:8000/push?cname=a&content=hello"
</pre>

<h3>Server push messages:</h3>
<div id="output"></div>

<script>
var count = 0;
var comet = new iComet({
	channel : 'a',
	subUrl : 'http://127.0.0.1:8100/sub',
	callback : function (content, type) {
		count ++;
		var output = document.getElementById('output');
		var time = '' + (new Date());
		output.innerHTML += count + '. ' + time + ': (' + type + ') ' + content + '<br/>';
	}
});
	
	
// var count = 0;
// var next_seq = 0;
// var last_script = null;
//
// function sub(seq){
// 	// setTimeout to get rid of loading status in browser status bar
// 	setTimeout(function(){
// 		next_seq = seq | 0;
// 		var body = document.getElementsByTagName('body')[0];
// 		var script = document.createElement('script');
// 		script.src = 'http://127.0.0.1:8100/sub?cname=a&cb=icomet_cb&seq=' + next_seq;
// 		if(last_script){
// 			body.removeChild(last_script);
// 		}
// 		body.appendChild(script);
// 		last_script = script;
// 	}, 0);
// }
//
// function icomet_cb(msg_data){
// 	if(msg_data instanceof Array){
// 		//
// 	}else{
// 		msg_data = [msg_data];
// 	}
// 	for(var k in msg_data){
// 		var msg = msg_data[k];
// 		if(msg.type == 'next_seq'){
// 			next_seq = parseInt(msg.seq);
// 			continue;
// 		}
// 		if(msg.type != 'data' && msg.type != 'broadcast'){
// 			continue;
// 		}
// 		if(msg.type == 'data'){
// 			next_seq = parseInt(msg.seq) + 1;
// 		}
// 		count ++;
// 		var output = document.getElementById('output');
// 		var time = '' + (new Date());
// 		output.innerHTML += count + '. ' + time + ': (' + msg.type + ') ' + msg.content + '<br/>';
// 	}
// 	// start next polling
// 	sub(next_seq);
// }
//
// sub();
</script>

</body>
</html>
